﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DAO;

namespace final.wuc
{
    public partial class wucdangbaiviet : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void imgpost_Click(object sender, ImageClickEventArgs e)
        {
            ArticleBUS articleBus = new ArticleBUS();
            TARTICLE t_article = articleBus.getAll().SingleOrDefault(n => n.ArticleName == txtTitle.Text.ToString());

            if (t_article != null) 
            { 
                DateTime now = DateTime.Now;
                txtTitle.Text += " (" + now.ToShortTimeString() + ")"; 
            }

            t_article = new TARTICLE();
            t_article.ArticleName = txtTitle.Text;
            t_article.ArticleInfo = txtContent.Text;
            
            if (articleBus.addArticle(t_article))
            {
                Response.Redirect("~/home.aspx");
            }
        }
    }
}